# -*- coding: utf-8 -*-

class ImagesController < ApplicationController
  def get_image
    #image = Image.find(params[:id])
    send_data(image.image_data, :disposition => "inline")
  end
  
  def get_images
    if params[:maker].blank? and params[:production].blank?
      @images = Image.select('id, image_type, maker, production').where(:image_type => params[:image_type]).all
    elsif not params[:maker].blank? and params[:production].blank?
      @images = Image.select('id, image_type, maker, production').where(:image_type => params[:image_type], :maker => params[:maker]).all
    elsif params[:maker].blank? and not params[:production].blank?
      @images = Image.select('id, image_type, maker, production').where(:image_type => params[:image_type], :production => params[:production]).all
    else
      @images = Image.select('id, image_type, maker, production').where(:image_type => params[:image_type], :maker => params[:maker], :production => params[:production]).all
    end
    text = ''
    @images.each do |i|
      text += '<a href="/admin_images/edit/'+i.id.to_s+'"><img src="/images/image/thumb/'+i.id.to_s+'.jpg" alt='+i.id.to_s+' align="left" /></a>'
    end
    render :text => text
  end
  
  def get_variable_images
    if params[:maker].blank? and params[:production].blank?
      @images = Image.select('id, image_type, maker, production').where(:image_type => params[:image_type]).all
    elsif not params[:maker].blank? and params[:production].blank?
      @images = Image.select('id, image_type, maker, production').where(:image_type => params[:image_type], :maker => params[:maker]).all
    elsif params[:maker].blank? and not params[:production].blank?
      @images = Image.select('id, image_type, maker, production').where(:image_type => params[:image_type], :production => params[:production]).all
    else
      @images = Image.select('id, image_type, maker, production').where(:image_type => params[:image_type], :maker => params[:maker], :production => params[:production]).all
    end
    text = ''
    @images.each do |i|
      text += '<img src="/images/image/thumb/'+i.id.to_s+'.jpg" alt='+i.id.to_s+' align="left" onclick="copy(this.src)" /></a>'
      text += '<img src="/images/image/middle/'+i.id.to_s+'.jpg" alt='+i.id.to_s+' align="left" onclick="copy(this.src)" /></a>'
      text += '<img src="/images/image/big/'+i.id.to_s+'.jpg" alt='+i.id.to_s+' onclick="copy(this.src)" /></a>'
    end
    render :text => text
  end
end
